package com.android.Bean;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.android.DBTools.ADUS;
import com.android.DBTools.DBConnection;
import com.android.ObjectBean.LinkManObjectList;

import net.sf.json.JSONArray;

public class LinkMainBean {
	// 添加联系人
	public void linkMainInsert(String linkName, String linkPhone, String linkEmail)
			throws ClassNotFoundException, SQLException {
		String sql = "INSERT INTO linkman (linkName,linkPhone,linkEmail) VALUES (\"" + linkName + "\",\"" + linkPhone + "\",\""
				+ linkEmail + "\");";
		ADUS.insertData(sql);
		DBConnection.closeCon();
	}

	// 查看联系人
	public String linkMainSelect() throws ClassNotFoundException, SQLException {
		String sql = "SELECT * FROM linkman";
		ResultSet rs = ADUS.selectData(sql);
		List<LinkManObjectList> list = new ArrayList<LinkManObjectList>();
		while (rs.next()) {
			LinkManObjectList sList = new LinkManObjectList();
			sList.setLinkID(rs.getString(rs.findColumn("linkID")));
			sList.setLinkName(rs.getString(rs.findColumn("linkName")));
			sList.setLinkPhone(rs.getString(rs.findColumn("linkPhone")));
			sList.setLinkEmail(rs.getString(rs.findColumn("linkEmail")));
			list.add(sList);
		}
		JSONArray json = JSONArray.fromObject(list);
		return json.toString();
	}
}
